package hczc.longcai.com.hccrowdfunding.home.second_invest.activities;

import android.content.Intent;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.ListView;
import android.widget.TextView;
import android.widget.Toast;

import java.util.ArrayList;
import java.util.List;

import hczc.longcai.com.hccrowdfunding.R;
import hczc.longcai.com.hccrowdfunding.activity.BaseActivity;
import hczc.longcai.com.hccrowdfunding.application.BaseApplication;
import hczc.longcai.com.hccrowdfunding.home.second_invest.adapters.ProjectDetailsAdapter;
import hczc.longcai.com.hccrowdfunding.home.second_invest.beans.ProjectDetail;
import hczc.longcai.com.hccrowdfunding.home.second_invest.beans.details_items.DetailReturn;

public class ChooseReturnActivity extends BaseActivity implements View.OnClickListener, ProjectDetailsAdapter.CallBack, AdapterView.OnItemClickListener {


    private static final String TAG = "ChooseReturnActivity";
    private ListView listView;
    private List<ProjectDetail> details;
    private ProjectDetailsAdapter adapter;
    private DetailReturn detailReturn2;
    private DetailReturn detailReturn;
    private List<DetailReturn> detailReturns;

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_choose_return);

        initDatas();
        initViews();
    }

    private void initDatas() {
        details = new ArrayList<>();
        detailReturns = new ArrayList<>();
        /**
         * ListView的头，标题
         */
        ProjectDetail detail1 = new ProjectDetail();
        detail1.setType(1);
        detail1.setTitle("镭射眼只能行车记录仪");
        details.add(detail1);
        /**
         * 分隔线
         */
        ProjectDetail detailFengexian1 = new ProjectDetail();
        detailFengexian1.setType(9);
        details.add(detailFengexian1);
        ProjectDetail detail2 = new ProjectDetail();
        detail2.setType(2);
        details.add(detail2);
        ProjectDetail detailFengexian3 = new ProjectDetail();
        detailFengexian3.setType(9);
        details.add(detailFengexian3);
        ProjectDetail detail4 = new ProjectDetail();
        detail4.setType(4);
        details.add(detail4);
        ProjectDetail detailFengexian4 = new ProjectDetail();
        detailFengexian4.setType(9);
        details.add(detailFengexian4);
        ProjectDetail detail5 = new ProjectDetail();
        detail5.setType(5);
        details.add(detail5);
        ProjectDetail detailFengexian5 = new ProjectDetail();
        detailFengexian5.setType(9);
        details.add(detailFengexian5);
        ProjectDetail detail6 = new ProjectDetail();
        detail6.setType(6);
        details.add(detail6);
        ProjectDetail detailFengexian6 = new ProjectDetail();
        detailFengexian6.setType(9);
        details.add(detailFengexian6);
        ProjectDetail detail7 = new ProjectDetail();
        detail7.setType(7);
        details.add(detail7);
        ProjectDetail detailFengexian7 = new ProjectDetail();
        detailFengexian7.setType(9);
        details.add(detailFengexian7);
        ProjectDetail detail8 = new ProjectDetail();
        detail8.setType(8);
        details.add(detail8);
        ProjectDetail detailFengexian8 = new ProjectDetail();
        detailFengexian8.setType(9);
        details.add(detailFengexian8);
        ProjectDetail detailReturnHead = new ProjectDetail();
        detailReturnHead.setType(11);
        details.add(detailReturnHead);
        ProjectDetail detail9 = new ProjectDetail();
        detailReturn = new DetailReturn();
        detailReturn.setSelected(true);
        detailReturn.setIndex(0);
        detailReturns.add(detailReturn);
        detail9.setaReturn(detailReturn);
        detail9.setType(10);
        details.add(detail9);
        ProjectDetail detail10 = new ProjectDetail();
        detailReturn2 = new DetailReturn();
//        detailReturn2.setSelected(false);
        detailReturn2.setIndex(1);
        detailReturns.add(detailReturn2);
        detail10.setaReturn(detailReturn2);
        detail10.setType(10);
        details.add(detail10);
        ProjectDetail detailFengexian9 = new ProjectDetail();
        detailFengexian9.setType(9);
        details.add(detailFengexian9);

    }

    private void initViews() {
        findViewById(R.id.head_back).setOnClickListener(this);
        listView = ((ListView) findViewById(R.id.invest_return_listview));
        ((TextView) findViewById(R.id.head_title)).setText("H基金");

        View view = LayoutInflater.from(this).inflate(R.layout.item_details_listview_header, listView, false);
        BaseApplication.scaleScreenHelper.loadView(((ViewGroup) view));

        listView.addHeaderView(view);
        adapter = new ProjectDetailsAdapter(this, details, this);
        listView.setAdapter(adapter);
        listView.setOnItemClickListener(this);

    }

    @Override
    public void onClick(View view) {
        int id = view.getId();
        switch (id) {
            case R.id.head_back:
                finish();
                break;


        }
    }

    @Override
    public void click(View view) {
        int id = view.getId();
        switch (id) {
            case R.id.detail_listview_return_choose_layout:
//                Toast.makeText(ChooseReturnActivity.this,"点击了选择按钮",Toast.LENGTH_SHORT).show();
                int tag = (int) view.getTag();
                int size = detailReturns.size();
                for (int i = 0; i < size; i++) {
                    detailReturns.get(i).setSelected(false);
                }
                detailReturns.get(tag).setSelected(true);
                adapter.notifyDataSetChanged();

                break;
            case R.id.detail_listview_attention:
                Toast.makeText(ChooseReturnActivity.this, "点击了关注按钮", Toast.LENGTH_SHORT).show();
                break;
            case R.id.detail_listview_zan_layout:
                Toast.makeText(ChooseReturnActivity.this, "点击了赞按钮", Toast.LENGTH_SHORT).show();
                break;
            case R.id.detail_listview_xmsm:
                Toast.makeText(ChooseReturnActivity.this, "点击了项目说明", Toast.LENGTH_SHORT).show();
                break;
            case R.id.detail_listview_xmjz_all:
//                Toast.makeText(ChooseReturnActivity.this,"点击了查看全部动态",Toast.LENGTH_SHORT).show();
                startActivity(new Intent(ChooseReturnActivity.this, ProjectDynamicActivity.class));

                break;
            case R.id.detail_listview_comment_all:
//                Toast.makeText(ChooseReturnActivity.this,"点击了查看所有评论",Toast.LENGTH_SHORT).show();
                startActivity(new Intent(ChooseReturnActivity.this, ProjectCommentActivity.class));

                break;

        }
    }

    @Override
    public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
//        Log.d(TAG,"点击了列表项");
    }
}
